package org.easy.socket.server.manager.impl;

import org.easy.socket.server.ClientSession;
import org.easy.socket.server.manager.IClientManager;
import org.easy.socket.server.manager.ISessionManager;
import org.smartboot.socket.transport.AioSession;

/**
 * @Description: 客户端连接管理器
 * @Author: wxl
 * @CreateTime: 2023/1/10 15:26
 */
public class ClientManager implements IClientManager {

    private final ISessionManager sessionManager;

    private ClientManager () {
        this.sessionManager = new SessionManager();
    }

    public static IClientManager getInstance () {
        return IClientManagerHolder.INSTANCE;
    }

    /**
     * 客户端会话管理
     * @param session 会话
     */
    @Override
    public void addSession(ClientSession session) {
        getSessionManager().addSession(session);
    }

    /**
     * 根据客户端ID删除
     *
     * @param clientId 客户端ID
     */
    @Override
    public void removeSession(String clientId) {
        getSessionManager().removeSession(clientId);
    }

    /**
     * 根据客户端ID获取会话
     *
     * @param clientId 客户端ID
     * @return AioSession
     */
    @Override
    public AioSession getSession(String clientId) {
        return getSessionManager().getSession(clientId);
    }

    public ISessionManager getSessionManager() {
        return sessionManager;
    }

    private static class IClientManagerHolder {
        private static final IClientManager INSTANCE = new ClientManager();
    }

}
